<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- CSS-->
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/main.css">
    <!-- Font-icon css-->
    <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
    <title>开发者登录</title>
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries-->
    <!--if lt IE 9
    script(src='https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js')
    script(src='https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js')
    -->
  </head>
  <body>
    <section class="material-half-bg">
      <div class="cover"></div>
    </section>
    <section class="login-content">
      <div class="logo">
        <h1>开发者平台</h1>
      </div>
      <div class="login-box<c:if test='${!empty regist}'> flipped</c:if>">
        <form class="login-form" action="<%=request.getContextPath()%>/devuser/login" method="post">
          <h3 class="login-head"><i class="fa fa-lg fa-fw fa-user"></i>登录</h3>
          <div class="form-group">
            <label class="control-label">用户名</label>
            <input class="form-control" type="text" name="devCode" <c:if test="${!empty loginUserInfo}">value="${loginUserInfo.devCode}"</c:if> placeholder="请输入昵称" autofocus>
          </div>
          <div class="form-group">
            <label class="control-label">密码</label>
            <input class="form-control" type="password" name="devPassword" placeholder="请输入密码">
          </div>
          <div class="form-group">
            <div class="utility">
              <div class="animated-checkbox">
                <label class="semibold-text">
                  <!--<input type="checkbox"><span class="label-text">Stay Signed in</span>-->
                </label>
              </div>
              <p class="semibold-text mb-0"><c:if test="${!empty loginInfo}"><span class="tip">${loginInfo}&nbsp;&nbsp;</span></c:if><a data-toggle="flip">未注册 ？去注册</a></p>
            </div>
          </div>
          <div class="form-group btn-container">
            <button class="btn btn-primary btn-block"><i class="fa fa-sign-in fa-lg fa-fw"></i>登录</button>
          </div>
        </form>
        <form id="registForm" class="forget-form" action="<%=request.getContextPath()%>/devuser/regist" method="post">
          <h3 class="login-head"><i class="fa fa-lg fa-fw fa-lock"></i>注册</h3>
          <div class="form-group">
            <label class="control-label">昵称</label><span></span>
            <input class="form-control" id="devCode" type="text" name="devCode" placeholder="请输入昵称" <c:if test="${!empty registUserInfo}"> value="${registUserInfo.devCode}"</c:if>>
            <label class="control-label">真实姓名</label><span></span>
            <input class="form-control" type="text" name="devName" placeholder="请输入姓名" <c:if test="${!empty registUserInfo}">value="${registUserInfo.devName}"</c:if>>
            <label class="control-label">密码</label><span></span>
            <input class="form-control" id="devPassword" type="password" name="devPassword" placeholder="请输入密码">
            <label class="control-label">确认密码</label><span></span>
            <input class="form-control" id="reDevPassword" type="password" name="devPassword2" placeholder="请再次输入密码">
            <label class="control-label">邮箱</label><span></span>
            <input class="form-control" id="devEmail" type="text" name="devEmail" placeholder="请输入邮箱" <c:if test="${!empty registUserInfo}">value="${registUserInfo.devEmail}"</c:if>>
            <label class="control-label"><a href="javascript:getEmailCode();">点击获取邮箱验证码</a></label>
            <c:if test="${!empty errEmailCode}"> <span class="tip">${errEmailCode}</span></c:if>
            <span></span>
            <input class="form-control" id="emailCode" type="text" name="emailCode" placeholder="请输入验证码" >
          </div>
          <div class="form-group btn-container">
            <button id="registButton" class="btn btn-primary btn-block"><i class="fa fa-unlock fa-lg fa-fw"></i>注册</button>
          </div>
          <div class="form-group mt-20">
            <p class="semibold-text mb-0"><a data-toggle="flip"><i class="fa fa-angle-left fa-fw"></i>登录</a>
              <c:if test="${!empty regist}"><span style="color: red"> &nbsp;&nbsp;${regist}</span></c:if>
            </p>
          </div>
        </form>
      </div>
    </section>
  </body>
  <script src="<%=request.getContextPath()%>/js/jquery-2.1.4.min.js"></script>
  <script src="<%=request.getContextPath()%>/js/bootstrap.min.js"></script>
  <script src="<%=request.getContextPath()%>/js/plugins/pace.min.js"></script>
  <script src="<%=request.getContextPath()%>/js/main.js"></script>
  <script type="text/javascript" charset="utf-8">
    $(function () {
        $("#devCode").blur(function () {
            checkDevCode();
        });
        $("#devEmail").blur(function () {
            checkEmail();
        });
        $("#registButton").click(function () {
            var past1 = checkDevCode();
            var past2 = checkEmail();
            if(past1&&past2){
                $("#registForm").submit();
            }
        });
    });
    /*测试用户帐号*/
    function checkDevCode() {
        var data = {"devCode":$("#devCode").val()};
        $.post("<%=request.getContextPath()%>/devuser/checkRegistCode",data,function (data) {
            if( data ){
                $("#devCode").prev().text("用户名可用！").css("color","green");
                return true;
            }else{
                $("#devCode").prev().text("用户名已存在，请更换！").css("color","red");
                return false;
            }
        });
    }
    /*测试用户邮箱*/
    function checkEmail() {
        var devEmail = $("#devEmail").val().trim();
        if( /^\d+@\w+(.\w+){1,2}$/.test(devEmail) ){
            $("#devEmail").prev().text("邮箱格式正确！").css("color","green");
            return true;
        }else{
            $("#devEmail").prev().text("邮箱格式错误，请重新填写！").css("color","red");
            return false;
        }
    }
    /*发送邮箱验证码*/
    function getEmailCode() {
        var data = {"devEmail":$("#devEmail").val(),"devCode":$("#devCode").val()};
        $.post("<%=request.getContextPath()%>/devuser/getEmailCode",data,function (data) {
            if( data ){
                $("#emailCode").prev().text("验证码已发送至邮件，请登录邮件获取验证码！").css("color","green");
                return true;
            }else{
                $("#emailCode").prev().text("验证码发送失败，请稍后再试！").css("color","red");
                return false;
            }
        });
    }
  </script>
</html>